<?php
/**
 * Created by PhpStorm.
 * User: zhangbing
 * Date: 2017/5/20
 * Time: 16:16
 */
namespace app\admin\validate;
use think\Validate;

class User extends Validate{
    //定义验证规则
    protected $rule = [
        'username' => 'require|length:11,11|unique:user',
        'password' => 'require|length:6,18',
        'nickname' => 'require|unique:user',
        'type_id'  => 'require',
        'up_id'    => 'require',
    ];

    //定义错误信息
    protected $message = [
        'username.require' => '用户名不能为空',
        'username.length'  => '用户名为11个字符',
        'username.unique'  => '用户名已存在',
        'password.require' => '密码不能为空',
        'password.length'  => '密码长度为6-18位',
        'nickname.require' => '昵称不能为空',
        'nickname.unique'  => '昵称已存在',
        'type_id.require'  => '用户类型不能为空',
        'up_id.require'  => '用户上级不能为空',
    ];

    //验证场景
    protected $scene = [
        'login'  =>  ['username','password'],
        'userAdd'  =>  ['username','nickname','type_id','up_id'],
        'userSave'  =>  ['nickname','type_id'],
        'businessAdd'  =>  ['username','nickname','type_id'],
        'businessSave'  =>  ['nickname','type_id'],
    ];
}
